package Simcomp::Random;
use strict;
use warnings;
our $VERSION = "0.01";
our @EXPORT = qw(getDistribution);
our @EXPORT_OK = qw( geraConstante geraExponencial geraNormal getDistribution );
our @EXPORT_TAGS = qw( all => [@EXPORT_OK] );


#constante
sub geraConstante {
    return $_[0];
}

#media (1/lambda)
sub geraExponencial {
    my $y = rand(1);
    return (-((log($y))*$_[0]));
}

#mediaX, desvioX
sub geraNormal 
{
    my ($sum, $y, $normX, $i);
    $sum = 0;
    for ($i=0; $i<12; $i++)
    {
	$y = rand(1);
	$sum += $y;
    }
    $normX = $_[1]*($sum-6.0)+$_[0];
    return $normX;
}

sub getDistribution
{

    my %function_hash = ( "exponencial" => \&geraExponencial, 
			  "normal" => \&geraNormal, 
			  "constante" => \&geraConstante );
    
    return $function_hash{ $_[0] };
	
}
